/*
*
* 版权所有 Copyleft(c) 2005
* 刘炯个人工作室 Sharp-Mark Personal Studio
*
* 允许自由使用，复制，修改，传播和贩卖此源程序及其文档，而不必支付任何费用。
* 以上的版权信息必须出现在每一份复制品中。同时这份版权信息和许可声明
* 也必须出现在支持文档中。刘炯个人工作室不对此软件适于那种具体
* 用途做出任何阐述。此代码只作为代码本身提供对其品质不做任何保证。
*
*/

// CppBase.cpp : 定义控制台应用程序的入口点。

#include "stdafx.h"
//#include "../SharpmarkGraphicsLib/Line/Line.h"

int _tmain(int argc, _TCHAR* argv[])
{
	//DDALine(0, 0, 4, 5, )

	cin.get();
	return 0;
}
/*
void PolyFillEdgeScan(CPolygon& polygon);
void FillTest()
{
	POINT points[6];
	points[0].x = 2;
	points[0].y = 2;

	points[1].x = 5;
	points[1].y = 1;

	points[2].x = 11;
	points[2].y = 3;

	points[3].x = 11;
	points[3].y = 8;

	points[4].x = 5;
	points[4].y = 5;

	points[5].x = 2;
	points[5].y = 7;

	CEdge edges[6];
	edges[0] = CEdge(points[0], points[1]);
	edges[1] = CEdge(points[1], points[2]);
	edges[2] = CEdge(points[2], points[3]);
	edges[3] = CEdge(points[3], points[4]);
	edges[4] = CEdge(points[4], points[5]);
	edges[5] = CEdge(points[5], points[0]);

	CPolygon polygon(edges, 6);
	PolyFillEdgeScan(polygon);
}*/

/*
void PrintList(list<CEdgeNode>& lst)
{
	for(list<CEdgeNode>::iterator lp = lst.begin(); lp != lst.end(); lp++)
	{
		cout << "(" << (*lp).X << ","  << (*lp).Dx << "," << (*lp).Y <<")";
	}

	cout << endl;
}

void PrintNET(CNewEdgeTable& t)
{
	int count = 0;
	for(vector< list<CEdgeNode> * >::iterator vp = t.Links.begin(); vp != t.Links.end(); vp++)
	{
		cout << "New Edge Table - Line : " << count << endl;

		PrintList(**vp);

		count ++;
	}
}

void PrintAET(CActiveEdgeTable& t)
{
	cout << "Active Edge Table: " << endl;

	PrintList(t.Link);
}
void PolyFillEdgeScan(CPolygon& polygon)
{
	// 确定上下边界
	int bottom = 100;
	int top = 0;

	for(int i = 0; i < polygon.Num; i++)
	{
		if( bottom >= polygon.Edges[i].yMin )
		{
			bottom = polygon.Edges[i].yMin;
		}

		if( top <= polygon.Edges[i].yMax )
		{
			top = polygon.Edges[i].yMax;
		}
	}

	//
	cout << "bottom =" << bottom << " top =" << top << endl;

	CNewEdgeTable net(top - bottom + 1);			// 生成NewEdgeTable.

	PrintNET(net);

	// 扫描各条边
	int b = bottom;
	for(vector< list<CEdgeNode> * >::iterator vp = net.Links.begin(); vp != net.Links.end(); vp++)
	{
		for(int j = 0; j < polygon.Num; j++)
		{
			//(*vp) = new list<CEdgeNode>;
			if(polygon.Edges[j].yMin == b)
			{
				//CEdgeNode * newNode = new CEdgeNode(polygon.Edges[i].xMin,
				//	polygon.Edges[i].dx, polygon.Edges[i].yMax);
				//(**lp).push_back(*newNode);

				(**vp).push_back(CEdgeNode((float)polygon.Edges[j].xMin,
					polygon.Edges[j].dx, polygon.Edges[j].yMax));
			}
		}
		b++;
	}

	//
	PrintNET(net);
	//

	float start, end;
	CActiveEdgeTable aet;

	//
	PrintAET(aet);
	//

	for(int i = 0; i <= top - bottom; i++ )
	{
		cout << "Now the line Y is " << i + bottom << endl;
		//
		PrintList(*(net.Links[i]));
		//

		aet.InsertNodes(net.Links[i]);

		for(list< CEdgeNode >::iterator p = aet.Link.begin(); p != aet.Link.end(); ++p)
		{
			start = (*p).X;
			p++;
			if(p == aet.Link.end()) break;
			end = (*p).X;
			if(start == end)
			{
				--p;
			}
			else
			{
				cout << "set pixel from " << start << " to" << end << endl << endl;
			}
		}

		for(list<CEdgeNode>::iterator p = aet.Link.begin(); p != aet.Link.end();)
		{
			if ((*p).Y == (i + bottom))
			{
				cout << "erase edge :" << "(" << (*p).X << ","  << (*p).Dx << "," << (*p).Y <<")" << endl;
				list<CEdgeNode>::iterator delp = p;
				p++;
				aet.Link.erase(delp);
			}
			else
			{
				cout << "Change X from " << (*p).X;
				(*p).X += (*p).Dx;
				cout << " To " << (*p).X << endl;
				p++;
			}
			
		}

		aet.Link.sort(CompareEdge());
	}
}*/